﻿using ClassLibrary;
using ClassLibrary.Randoms;
using ClassLibrary.Realization;
using MixedOperation;
using ProperFraction;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using TitleText;

namespace WPFapplication
{
    /// <summary>
    /// LoginSuccessful.xaml 的交互逻辑
    /// </summary>
    public partial class LoginSuccessful : Window
    {
        public static int dui { get; set; }//记录全部答对的
        public static int cuo { get; set; }//记录全部答错的

        Operation test = new Operation();//混合运算
        RandomQuestions randomQuestions = new RandomQuestions();//一年级
        //二年级加减乘除
        Addition addition = new Addition();//加
        Subtraction subtraction = new Subtraction();//减
        Multiplication multiplication = new Multiplication();//乘
        Division division = new Division();//除

        FractionFourOperations fractionFourOperations = new FractionFourOperations();//三年级
        Realization realization = new Realization();//二年级
        public LoginSuccessful()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)//一年级显示题目
        {
            a.Clear();
            this.listBox.ItemsSource = randomQuestions.RunAll(10, 1, 10);
            a = randomQuestions.RunValue();

        }
        public void all(List<string> vs)
        {
            if (listBox.SelectedIndex > vs.Count || listBox.SelectedIndex == -1)
            {
                return;
            }
            else
            {
                if (vs[listBox.SelectedIndex] == txt2.Text.Trim())
                {
                    lisbox2.Items.Add(txt1.Text.Trim().Substring(0, txt1.Text.Length - 1) + txt2.Text.Trim() + "  √");
                    dui += 1;
                }
                else
                {
                    lisbox2.Items.Add(txt1.Text.Trim().Substring(0, txt1.Text.Length - 1) + txt2.Text.Trim() + "  ×");
                    cuo += 1;
                }

            }

        }

        List<string> a = new List<string>();
        List<string> add = new List<string>();
        List<string> sub = new List<string>();
        List<string> mul = new List<string>();
        List<string> div = new List<string>();
        List<decimal> hh = new List<decimal>();
        List<string> daan = new List<string>();

        private void Button_Click_1(object sender, RoutedEventArgs e)//答题显示
        {
            if (secondGrade2.SelectedIndex == 1)
            {
                if (txt2.Text == "")
                {
                    MessageBox.Show("请输入答案");
                    return;
                }
                else
                {
                    all(add);
                }
            }
            else if (secondGrade2.SelectedIndex == 2)
            {
                if (txt2.Text == "")
                {
                    MessageBox.Show("请输入答案");
                    return;
                }
                else
                {
                    all(sub);
                }
            }
            else if (secondGrade2.SelectedIndex == 3)
            {
                if (txt2.Text == "")
                {
                    MessageBox.Show("请输入答案");
                    return;
                }
                else
                {
                    all(mul);
                }
            }
            else if (secondGrade2.SelectedIndex == 4)
            {
                if (txt2.Text == "")
                {
                    MessageBox.Show("请输入答案");
                    return;
                }
                else
                {
                    all(div);
                }
            }
            else if (san.SelectedIndex == 1)
            {
                if (txt2.Text == "")
                {
                    MessageBox.Show("请输入答案");
                    return;
                }
                else
                {
                    all(daan);
                }
            }
            else if (san.SelectedIndex == 2)
            {
                if (txt2.Text == "")
                {
                    MessageBox.Show("请输入答案");
                    return;
                }
                else
                {
                    all(daan);
                }
            }
            else if (san.SelectedIndex == 3)
            {
                if (txt2.Text == "")
                {
                    MessageBox.Show("请输入答案");
                    return;
                }
                else
                {
                    all(daan);
                }
            }
            else if (san.SelectedIndex == 4)
            {
                if (txt2.Text == "")
                {
                    MessageBox.Show("请输入答案");
                    return;
                }
                else
                {
                    all(daan);
                }
            }
            else if (si.SelectedIndex == 1)
            {

                if (txt2.Text == "")
                {
                    MessageBox.Show("请输入答案");
                    return;
                }
                else
                {
                    if (hh[listBox.SelectedIndex].ToString() == txt2.Text.Trim())
                    {
                        lisbox2.Items.Add(txt1.Text.Trim().Substring(0, txt1.Text.Length - 1) + txt2.Text.Trim() + "  √");
                        dui += 1;
                    }
                    else
                    {
                        lisbox2.Items.Add(txt1.Text.Trim().Substring(0, txt1.Text.Length - 1) + txt2.Text.Trim() + "  ×");
                        cuo += 1;
                    }
                }

            }
            else if (si.SelectedIndex == 2)
            {
                if (txt2.Text == "")
                {
                    MessageBox.Show("请输入答案");
                    return;
                }
                else
                {

                    if (hh[listBox.SelectedIndex].ToString() == txt2.Text.Trim())
                    {
                        lisbox2.Items.Add(txt1.Text.Trim().Substring(0, txt1.Text.Length - 1) + txt2.Text.Trim() + "  √");
                    }
                    else
                    {
                        lisbox2.Items.Add(txt1.Text.Trim().Substring(0, txt1.Text.Length - 1) + txt2.Text.Trim() + "  ×");

                    }
                }

            }
            else if (btnone.Content.ToString() == "一年级")
            {
                if (txt2.Text == "")
                {
                    MessageBox.Show("请输入答案");
                    return;
                }
                else
                {
                    all(a);
                }
            }

            //这里else if判断功能

            else
            {
                MessageBox.Show("选择错误");
            }
            txt2.Text = "";
        }
        private void listBox_MouseDoubleClick(object sender, MouseButtonEventArgs e)//列表显示选定
        {
            var SelectItems = listBox.Items;

            for (int i = 0; i < SelectItems.Count; i++)
            {
                txt1.Text = listBox.SelectedItem.ToString();

            }
            txt2.Text = "";

        }
        private void ComboBox_SelectionChanged_1(object sender, SelectionChangedEventArgs e)//三年级题目显示
        {
            daan.Clear();
            switch (san.SelectedIndex)
            {

                case 1:
                    this.listBox.ItemsSource = fractionFourOperations.runjia(10);
                    daan = fractionFourOperations.Value;
                    break;
                case 2:
                    this.listBox.ItemsSource = fractionFourOperations.runjian(10);
                    daan = fractionFourOperations.Value;
                    break;
                case 3:
                    this.listBox.ItemsSource = fractionFourOperations.runcheng(10);
                    daan = fractionFourOperations.Value;
                    break;
                case 4:
                    this.listBox.ItemsSource = fractionFourOperations.runchu(10);
                    daan = fractionFourOperations.Value;
                    break;
            }

        }

        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)//二年级题目显示
        {
            add.Clear();
            sub.Clear();
            mul.Clear();
            div.Clear();
            var io = secondGrade2.SelectedIndex;
            switch (io)
            {
                case 1:
                    this.listBox.ItemsSource = addition.RunAll(10);
                    add = addition.RunValue();
                    break;
                case 2:
                    this.listBox.ItemsSource = subtraction.RunAll(10);
                    sub = subtraction.RunValue();
                    break;
                case 3:
                    this.listBox.ItemsSource = multiplication.RunAll(10);
                    mul = multiplication.RunValue();
                    break;
                case 4:
                    this.listBox.ItemsSource = division.RunAll(10);
                    div = division.RunValue();
                    break;
            }
        }
        //private void Button_Click_2(object sender, RoutedEventArgs e)
        //{
        //    this.listBox.ItemsSource = test.GetSum(10, 4, false);
        //    hh = test.Value;
        //    btnone.IsEnabled = false;           
        //    secondGrade2.IsEnabled = false;
        //    san.IsEnabled = false;

        //}

        //private void Button_Click_3(object sender, RoutedEventArgs e)
        //{
        //    this.listBox.ItemsSource = test.GetSum(10, 4, true);
        //    hh = test.Value;
        //    btnone.IsEnabled = false;           
        //    secondGrade2.IsEnabled = false;
        //    san.IsEnabled = false;

        //}
        public static string results()//统计结果！
        {
            return $"总共做了{dui + cuo}道题：做对了{dui}道题,做错了{cuo}道题。";
        }
        private void Button_Click_4(object sender, RoutedEventArgs e)
        {
            lj.Content = results();
        }

        //private void Button_Click_5(object sender, RoutedEventArgs e)
        //{
        //    ////这里接收答案
        //    a.Clear();
        //    add.Clear();
        //    sub.Clear();
        //    mul.Clear();
        //    div.Clear();
        //    hh.Clear();
        //    daan.Clear();
        //    btnone.IsEnabled = true;           
        //    secondGrade2.IsEnabled = true;
        //    san.IsEnabled = true;          
        //    txt1.Text = "";
        //    txt2.Text = "";
        //    listBox.ItemsSource = null;

        //}

        private void si_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            a.Clear();
            add.Clear();
            sub.Clear();
            mul.Clear();
            div.Clear();
            daan.Clear();
            hh.Clear();
            var io = si.SelectedIndex;
            switch (io)
            {
                case 1:
                    this.listBox.ItemsSource = test.GetSum(10, 4, false);
                    hh = test.Value;
                    break;
                case 2:
                    this.listBox.ItemsSource = test.GetSum(10, 4, true);
                    hh = test.Value;
                    break;
            }
        }
    }
}
